%
function out = frameEnergy(u,wu,gw,c,f,nu)
global nPhases nLevels
global M N
global HD
    out = 0;
    for i = 1 : nPhases
        s = zeros(M,N);
        for j = 1 : nLevels 
            tmpy = gw.*wu{i}{j};
                for l = 1 : numel(HD)
                    for q = 1 : numel(HD)
                        s = s + tmpy((l-1)*M+1:l*M,(q-1)*N+1:q*N).^2;
                    end
                end
        end
        s = sqrt(s);
        out = out + sum(s(:));
    end
    for i = 1 : nPhases
        tmp=0.5*nu*(c(i)-f).^2.*u{i};
        out = out + sum(tmp(:));
    end
end



    